from flask import Flask, request, jsonify
from flask_cors import CORS
import sys
import json
sys.path.append(r"D:/yolo3-keras")
# import fuck_realtime


# import tensorflow as tf
# graph = tf.get_default_graph()

app = Flask(__name__)
CORS(app)
frames = []
done = False
# yolo = YOLO()


@app.route('/')
def hello_world():
    return 'Hello World!'

@app.route('/path',methods = ["GET","POST"])
def hello():

    path = request.args.get('path')
    done = fuck_realtime(path)    
    path = request.args.get('path')
    alljsonstr = []
    with open('../predict-img/' + path + '/' + path + 'car.json', 'r') as f:
        data = json.load(f)
        # carjsonstr = json.dumps(data)
        alljsonstr.append(data)
    with open('../predict-img/' + path + '/' + path + 'jsonframe.json', 'r') as f:
        data = json.load(f)
        # framejsonstr = json.dumps(data)
        alljsonstr.append(data)
    return json.dumps(alljsonstr)


@app.route('/frame', methods = ["GET", "POST"])
def frame():
    global frames
    id = request.args.get("id")
    while len(frames) < id:
        continue
    return frames[id - 1]

if __name__ == '__main__':
    app.run()

# yolo.close_session()


def fuck(current_img):
    frames.append(current_img)
    # print(frames)

